<?php
/**
 * Created by PhpStorm.
 * User: function
 * Date: 2018-04-12
 * Time: 9:08
 */

namespace app\admin\controller;
use app\common\controller\Admin;
use app\common\model\Goods;
use app\common\logic\GoodsLogic;
use app\common\model\Company;
class Mall extends Admin
{
    public function index()
    {
        
        $logic = new GoodsLogic();
    
        $params = paramForm();
       
        if(\think\Request::instance()->isAjax()){
            $params['paginate'] = 1;
            
            if (isset($params['title'])){
                $params['title'] = array('like','%'.$params['title'].'%');
            }
    
            if (isset($params['company'])){
                $sellers = Company::where('company','like','%'.$params['company'].'%')->field('user_id')->select();
                $params['user_id'] = array('in',$sellers);
            }
           
            $categoryList = $logic->getList($params);
            success($categoryList);
        }else{
           
            return $this->fetch();
        
        }
        
    }
    
    public function down($id){
        
        $id = paramForm('id');
        $logic = new GoodsLogic();
        $rt = $logic->changeGoodsStatus($id,0);
        if($rt){
            $this->success('操作成功');
        }else{
            $this->error('操作失败');
        }
        
    }
    
    public function up($id){
        $id = paramForm('id');
        $logic = new GoodsLogic();
        $rt = $logic->changeGoodsStatus($id,3);
        if($rt){
            $this->success('操作成功');
        }else{
            $this->error('操作失败');
        }
        
    }
    
}